/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using VSLangProj80;
using System.Collections.ObjectModel;

namespace DaveSexton.DocProject
{
	internal sealed class KeyedProjectCollection<TProject> : KeyedCollection<string, TProject>
		where TProject : IAnyProject
	{
		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="KeyedProjectCollection" /> class.
		/// </summary>
		public KeyedProjectCollection()
		{
		}
		#endregion

		#region Methods
		public static string GetProjectKey(TProject project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			return project.FilePath;
		}

		public static KeyedProjectItem CreateKeyedProjectItem(TProject project)
		{
			if (project == null)
				throw new ArgumentNullException("project");
			
			return new KeyedProjectItem(project.Name, GetProjectKey(project));
		}

		protected override string GetKeyForItem(TProject item)
		{
			return GetProjectKey(item);
		}

		protected override void InsertItem(int index, TProject item)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			base.InsertItem(index, item);
		}

		protected override void SetItem(int index, TProject item)
		{
			if (item == null)
				throw new ArgumentNullException("item");

			base.SetItem(index, item);
		}
		#endregion
	}
}
